package com.example.chapter11;


import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/*
* 11.3.函数式编程任务实施
* */
public class Demo07 {


    public static class Employee {
        private String name;
        private int age;
        private double salary;

        public Employee(String name, int age, double salary) {
            this.name = name;
            this.age = age;
            this.salary = salary;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public double getSalary() {
            return salary;
        }

        public void setSalary(double salary) {
            this.salary = salary;
        }
    }

    public static void main(String[] args) {
        List<Employee> employees = Arrays.asList(
                new Employee("张三", 28, 8000),
                new Employee("李四", 35, 12000),
                new Employee("王五", 32, 10000),
                new Employee("赵六", 29, 9000),
                new Employee("孙七", 37, 13000)
        );

        // 1. 筛选出年龄大于30岁的员工
        List<Employee> filteredEmployees = employees.stream()
                .filter(e -> e.getAge() > 30)
                .collect(Collectors.toList());

        // 2. 对筛选出的员工按照薪水从高到低进行排序
        List<Employee> sortedEmployees = filteredEmployees.stream()
                .sorted(Comparator.comparingDouble(Employee::getSalary).reversed())
                .collect(Collectors.toList());

        // 3. 取出薪水最高的前三名员工
        List<Employee> topThreeEmployees = sortedEmployees.stream()
                .limit(3)
                .collect(Collectors.toList());

// 4. 打印这三名员工的姓名和薪水
        topThreeEmployees.forEach(e -> System.out.println("姓名：" + e.getName() + "，薪水：" + e.getSalary()));
    }
}
